package com.wushi.lenovo.asia5b.app_ui.pay.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.mvp.base.BaseSimpleFragment;
import com.mvp.base.model.ResultModel;
import com.mvp.helper.WCallBack;
import com.mvp.utils.StringUtils;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_model.credit.bean.TopupInfoBean;
import com.wushi.lenovo.asia5b.app_model.other.WebUrlType;
import com.wushi.lenovo.asia5b.app_ui.other.dialog.trans.OrderPayDFragment;
import com.wushi.lenovo.asia5b.app_ui.pay.activity.PayActivity;
import com.wushi.lenovo.asia5b.app_utils.eye.EyeUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by zhangyuncai on 2020/3/4.
 * 订单支付余额充足
 */
public class PaySufficientFragment extends BaseSimpleFragment {
    @BindView(R.id.tv_pay_balance)
    TextView tv_pay_balance;
    @BindView(R.id.tv_pay_payprice)
    TextView tv_pay_payprice;
    @BindView(R.id.tv_pay_orderprice)
    TextView tv_pay_orderprice;
    @BindView(R.id.tv_paysufficient_notice)
    TextView tv_paysufficient_notice;
    private PayActivity payActivity;
    public TopupInfoBean topupInfoBean = null;
    @Override
    protected int getLayout() {
        return R.layout.fragment_paysufficient;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        payActivity= (PayActivity) mActivity;
        topupInfoBean=payActivity.topupInfoBean;
        initView();
        initEvent();
    }

    @Override
    protected void initView() {
        tv_pay_payprice.setText(StringUtils.formatNum2(topupInfoBean.getTotalAmount()));
        tv_pay_orderprice.setText(String.format("%s %s", getString(R.string.rm), StringUtils.formatNum2(topupInfoBean.getTotalAmount())));
        tv_pay_balance.setText(topupInfoBean.getBalance_value());

        EyeUtils.setLinkText(mActivity, getString(R.string.shopcar_pi_notice), getString(R.string.shopcar_pi_notice_key),
                tv_paysufficient_notice, WebUrlType.shopcar_pi);

    }

    @Override
    protected void lazyFetchData() {

    }
    private void showTransferDialog() {
        OrderPayDFragment orderPayDFragment = (OrderPayDFragment) OrderPayDFragment.instantiate(mActivity, OrderPayDFragment.class.getName());
        orderPayDFragment.setData(topupInfoBean);
        orderPayDFragment.show(getChildFragmentManager(), getClass().getName());
        orderPayDFragment.setCallBack(new WCallBack<ResultModel>() {
            @Override
            public void callback(ResultModel resultModel) {
                if (resultModel.isSuccess()) {
                    orderPayDFragment.setOnDismissListener(dialog -> {
                        payActivity.finish();
                    });
                }
            }
        });


    }
    @Override
    protected void initEvent() {

    }

    @OnClick({
            R.id.bt_pay_ok
    })
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_pay_ok: {
                showTransferDialog();
            }
            break;
            default:
                break;
        }
    }
}
